﻿@model GolfLeague.EditModels.ScoringMethodEditModel

<script type="text/javascript">

    $(document).ready(function () {
        $('#dialog').dialog({
            autoOpen: false,
            model: true
        });
        $('input:button').button();
        $('input:reset').button();
        $('input:submit').button();
        $('div#buttonlist a').hover(
		    function () { $(this).addClass('ui-state-hover'); },
		    function () { $(this).removeClass('ui-state-hover'); }
	    );
    });

    $(function () {
        $('.DeleteButton').click(function (e) {
            e.preventDefault();
            var recordToDelete = $(this).attr('id');
            recordToDelete = recordToDelete.replace('delete-', '');

            $('#dialog').dialog('option', 'buttons', {
                'Yes': function () {
                    $(this).dialog('close');
                    if (recordToDelete != '') {
                        $.post('/ScoringMethod/Delete', { 'scoringMethodID': recordToDelete },
                        function (data) {
                            $('#row-' + recordToDelete).fadeOut('slow');
                        });
                    }
                },
                'No': function () {
                    $(this).dialog('close');
                    return false;
                }
            });
            $('#dialog').dialog('open');
        });
    });

    $(function () {
        $('.EditButton').click(function (e) {
            e.preventDefault();
            var recordToEdit = $(this).attr('id');
            recordToEdit = recordToEdit.replace('edit-', '');

            if (recordToEdit != '') {
                window.location = '/ScoringMethod/Edit/' + recordToEdit;
            }
        });
    });

    $(function () {
        $('.CancelEditButton').click(function (e) {
            e.preventDefault();
            window.location = '/ScoringMethod/';
        });
    });

</script>

@{
    ViewBag.Title = "ScoringMethods";
}

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Add Scoring Method</legend>

        @Html.HiddenFor(model => model.NewScoringMethod.ScoringMethodID)

        <div class="editor-label">
            @Html.LabelFor(model => model.NewScoringMethod.ScoringMethodName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.NewScoringMethod.ScoringMethodName)
            @Html.ValidationMessageFor(model => model.NewScoringMethod.ScoringMethodName)
        </div>
        <fieldset>
            <legend>Points</legend>
            <br />
            <table>
                <tr>
                    <th style="text-align:center">Per<br />Hole</th>
                    <th style="text-align:center">Per<br />Match</th>
                    <th style="text-align:center">Bonus</th>
                </tr>
                <tr align="center">
                    <td>@Html.TextBoxFor(model => model.NewScoringMethod.HolePoints, new { @class="HoleInput" })</td>
                    <td>@Html.TextBoxFor(model => model.NewScoringMethod.MatchPoints, new { @class="HoleInput" })</td>
                    <td>@Html.TextBoxFor(model => model.NewScoringMethod.BonusPoints, new { @class="HoleInput" })</td>
                </tr>
            </table>
        </fieldset>

        <div class="editor-label">
            @Html.LabelFor(model => model.NewScoringMethod.ScoringTypeID)
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.NewScoringMethod.ScoringTypeID, new SelectList(Model.ScoringTypeDropdown, "dropdownID", "dropdownText", Model.NewScoringMethod.ScoringTypeID))
            @Html.ValidationMessageFor(model => model.NewScoringMethod.ScoringTypeID)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.NewScoringMethod.ScoringCalculationID) @Html.ActionLink("View", "ScoringCalculations")
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.NewScoringMethod.ScoringCalculationID, new SelectList(Model.ScoringCalcuationDropdown, "dropdownID", "dropdownText", Model.NewScoringMethod.ScoringCalculationID))
            @Html.ValidationMessageFor(model => model.NewScoringMethod.ScoringCalculationID)
        </div>

        <p>
        @if (Model.NewScoringMethod.ScoringMethodID < 1)
        {
            <input type="submit" value="Add" />
        }
        else
        {
            <input type="submit" value="Save" />
            <input type="reset" class="CancelEditButton" value="Cancel" />
        }
        </p>
        <div id="dialog" title="Confirm Delete">Are you sure you want to delete this scoring method?</div>
    </fieldset>
}


<fieldset>
    <legend>Scoring Methods</legend>
    <table>
        <tr align="center">
            <th rowspan="2">
                Name
            </th>
            <th rowspan="2">
                Scoring Type
            </th>
            <th colspan="3" style="text-align:center">
                Points
            </th>
            <th rowspan="2">
                Scoring Calculation
            </th>
            <th rowspan="2"></th>
        </tr>
        <tr>
            <th style="text-align:center">Hole</th>
            <th style="text-align:center">Match</th>
            <th style="text-align:center">Bonus</th>
        </tr>
@foreach (var item in Model.ScoringMethods) {
        <tr id="row-@item.ScoringMethodID">
            <td>
                @item.ScoringMethodName
            </td>
            <td>
                @item.ScoringType.ScoringTypeName
            </td>
            <td>
                @item.HolePoints
            </td>
            <td>
                @item.MatchPoints
            </td>
            <td>
                @item.BonusPoints
            </td>
            <td>
                @item.ScoringCalculation.CalculationName
            </td>
            <td>
                <div id="buttonlist" style="vertical-align:middle">
                    <a href="#" title="Edit Scoring Method" class="EditButton ui-state-default ui-corner-all ui-icon ui-icon-pencil" id="edit-@item.ScoringMethodID"></a>
                    <a href="#" title="Delete Scoring Method" class="DeleteButton ui-state-default ui-corner-all ui-icon ui-icon-trash" id="delete-@item.ScoringMethodID"></a>
                </div>
            </td>
        </tr>
}
    </table>
</fieldset>